<?php

class Email extends Controller 
{
	function Email()
	{
		// load controller parent
		parent::Controller();

		// load 'url' helper
		$this->load->helper('url');

		// load 'form' helper
		$this->load->helper('form');

		// load 'validation' class
		$this->load->library('validation');

		// load 'email' class
		$this->load->library('email');
	}

	function index()
	{
		// set validation rules
		$rules['firstname']="required|min_length[6]|max_length[15]";
		$rules['lastname']="required|min_length[6]|max_length[15]";
		$rules['email']="required|valid_email";
		$this->validation->set_rules($rules);

		// set values to repopulate fields
		$fields['firstname']='First Name';
		$fields['lastname']= 'Last Name';
		$fields['email']='Email Address';
		$this->validation->set_fields($fields);

		// check if user form has been submitted properly
		if ($this->validation->run()==FALSE)
		{
			// redisplay user form and repopulate fields
			$this->load->view('form_view');
		}
		// display confirmation web page and send email
		else
		{
			// set email class settings
			$this->email->from('harsha_bhogle@example.com', 'Harsha Bhogle');
			$this->email->to('raz_0007@hotmail.com');
			$this->email->cc('has_9@hotmail.com');
			$this->email->bcc('has9live@yahoo.com');
			$this->email->subject('I am interested in your website proposal!');
			$this->email->message("Hello newgenbd software. I am Harsha Bhogle the Indian cricket commentator. Some time back I had received an twitter message regarding a free website. I have now decided to have it. If you guys want to contact then please do so by replying to my email above.
			Sincerely, Harsha Bhogle
			");
			$data['title']='Sending email...';
			

			
			
			
			$data['header']='Sending email now...';
			$data['message']=$this->email->send()?'Message was sent successfully!':'Error sending email!';
			$this->load->view('email_view.php',$data);
		}
	}
}

?>